// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from "vue";
import App from "./App";
import router from "./router";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import MintUI from "mint-ui";
import "mint-ui/lib/style.css";
import { Navbar, TabItem } from "mint-ui";
import { Picker, Popup, Actionsheet } from "mint-ui";
import LyTab from "ly-tab";
import VueAwesomeSwiper from "vue-awesome-swiper";
import "swiper/dist/css/swiper.css";
import VideoPlayer from "vue-video-player"; // video
import utils from "@/utils/utils.js";
import { getOpenidAPI } from "@/api/order.js";
import VueTouch from "vue-touch";
import FastClick from "fastclick";
import Vant from "vant";
import { SwipeCell } from "vant";
//import  'amfe-flexible';
import "vant/lib/index.css";
import "./utils/common.js"; //公共js
// import VConsole from "vconsole";
// const isDebug = true;
// // 本地开发调试注入vConsole
// if (isDebug) {
//   new VConsole();
// }

FastClick.attach(document.body);


Vue.component(Picker.name, Picker);
Vue.component(Popup.name, Popup);
Vue.component(Actionsheet.name, Actionsheet);
Vue.component(Navbar.name, Navbar);
Vue.component(TabItem.name, TabItem);
Vue.config.productionTip = false;

Vue.use(Vant);
Vue.use(SwipeCell);
Vue.use(ElementUI);
Vue.use(MintUI);
Vue.use(LyTab);
Vue.use(VueAwesomeSwiper);
Vue.use(VueTouch, { name: "v-touch" });
VueTouch.config.swipe = {
  threshold: 100 //手指左右滑动距离
};
// 封面
//默认封面
Vue.prototype.notFind = function(params) {
  let img = event.srcElement;
  img.src = require("@/assets/course/cover.png");
  img.onerror = null; //防止闪图
};

// 默认头像
Vue.prototype.notImg = function(params) {
  let img = event.srcElement;
  img.src = require("@/assets/common/cover.png");
  img.onerror = null; //防止闪图
};
//判断是否登录
Vue.prototype.isLogin = function(params) {
  if (!localStorage.getItem("y-token")) {
    //判断是否登录
    this.$router.replace({
      name: "login",
      query: { routerUrl: this.$router.currentRoute.fullPath }
    });
    return false;
  } else {
    return true;
  }
};

/* eslint-disable no-new */
new Vue({
  el: "#app",
  // appBack,
  router,
  components: { App },
  template: "<App/>"
});

router.beforeEach(({ meta, path }, from, next) => {
  document.title = meta.title; /* 路由发生变化修改页面title */
  next();
  window.scrollTo(0, 0)
  // if (!localStorage.getItem('openId') && /MicroMessenger/.test(window.navigator.userAgent)) { //微信浏览器提前授权
  //   console.log(122222)
  //   let wxUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxdee4149de87badc3&redirect_uri='
  //   let usUrl = 'http://192.168.2.247/wap/demo.html'
  //   // let usUrl = 'http://192.168.2.247'
  //   window.location.href = wxUrl + usUrl + '&response_type=code&scope=snsapi_base&state=' + path + '&connect_redirect=1#wechat_redirect'
  // }
})

router.afterEach(({ meta, path }, from, next) => {
  //微信浏览器获取用户openid--授权
  window.scrollTo(0, 0);
  // if (
  //   utils.getUrlKey("code") &&
  //   !localStorage.getItem("openId") &&
  //   /MicroMessenger/.test(window.navigator.userAgent)
  // ) {
  //   console.log(utils.getUrlKey("code"), "aabb");
  //   getOpenidAPI({ code: utils.getUrlKey("code") }).then(res => {
  //     //请求接口获取openId
  //     console.log(res, "resccddee");
  //     if (res.data.code == 0) {
  //       localStorage.setItem("openId", res.data.data.openid);
  //     }
  //   });
  // }
});
